package com.symaster.common.swing.dialog;

import com.symaster.common.swing.config.AppConfig;
import com.symaster.common.event.ReSizeEvent;
import com.symaster.common.swing.listener.SystemShortcutManager;
import com.symaster.common.swing.style.Style;
import com.symaster.common.swing.util.SwingUtil;

import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import java.awt.*;

public class SyzdLoadingDialog extends JFrame {
    private JPanel root_panel;
    private JTextField tips_text;
    private ReSizeEvent reSizeEvent;

    public SyzdLoadingDialog() {
        initPage();
        initListener();
    }

    public static void main(String[] args) {
        SyzdLoadingDialog dialog = new SyzdLoadingDialog();
        dialog.setVisible(true);
    }

    private void initListener() {
        SystemShortcutManager.addListener(1, SystemShortcutManager.MOD_NONE, SystemShortcutManager.ESC, identifier -> System.exit(-1));
    }

    public void addWindowChangeListener(ReSizeEvent.WindowChangeListener listener) {
        reSizeEvent.addWindowChangeListener(listener);
    }

    public void removeWindowChangeListener(ReSizeEvent.WindowChangeListener listener) {
        reSizeEvent.removeWindowChangeListener(listener);
    }

    private void initPage() {
        setContentPane(root_panel);

        tips_text.setEditable(false);
        tips_text.setEditable(false);
        tips_text.setForeground(AppConfig.getColor(AppConfig.SELECT_COLOR));
        tips_text.setText("程序启动中...");
        Style.setFont(1, tips_text);
        Style.setBorder(1, tips_text);

        int width = 600;
        int height = 300;
        setPreferredSize(new Dimension(width, height));
        setMinimumSize(new Dimension(width, height));

        reSizeEvent = new ReSizeEvent(this);
        addMouseListener(reSizeEvent);
        addMouseMotionListener(reSizeEvent);

        root_panel.setBorder(new LineBorder(new Color(249, 130, 108), 1));
        setContentPane(root_panel);
        setUndecorated(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pack();
        SwingUtil.toCenter(this);
    }

    {
        // GUI initializer generated by IntelliJ IDEA GUI Designer
        // >>> IMPORTANT!! <<<
        // DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        root_panel = new JPanel();
        root_panel.setLayout(new BorderLayout(0, 0));
        root_panel.setBackground(new Color(-14407378));
        root_panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new BorderLayout(0, 0));
        panel1.setBackground(new Color(-14407378));
        panel1.setPreferredSize(new Dimension(0, 27));
        root_panel.add(panel1, BorderLayout.SOUTH);
        panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        tips_text = new JTextField();
        tips_text.setBackground(new Color(-14407378));
        tips_text.setHorizontalAlignment(0);
        panel1.add(tips_text, BorderLayout.CENTER);
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new BorderLayout(0, 0));
        panel2.setBackground(new Color(-14407378));
        root_panel.add(panel2, BorderLayout.CENTER);
        panel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
    }

    /** @noinspection ALL */
    public JComponent $$$getRootComponent$$$() {
        return root_panel;
    }

}
